package personal.xjl.studentdemo.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import personal.xjl.studentdemo.dao.StudentMapper;
import personal.xjl.studentdemo.entity.Student;
import personal.xjl.studentdemo.service.StudentService;

import java.util.List;
@Service  //spring容器将创建一个对象，名字是studentServiceImpl,studentController调用

public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;
    @Override
    public int addStudent(Student student) {
        return studentMapper.insert(student);
    }

    @Override
    public int deleteStudent(int id) {
       return studentMapper.deleteById(id);
    }

    @Override
    public List<Student> getStudents() {
        return studentMapper.findAll(0,3);
    }

    @Override
    public Student selectById(int id) {
        return studentMapper.selectById(id);
    }

    @Override
    public int edit(Student student) {
        return studentMapper.update(student);
    }

    @Override
    public boolean login(String username, String password) {
        return !studentMapper.selectByUsernameAndPass(username, password).isEmpty();
    }

    @Override
    public List<Student> selectByPage(int fromIndex, int pageSize) {
        return studentMapper.findAll(fromIndex, pageSize);
    }

}
